<template>
	<view>
		<view class="block dingwei mainpadding" style="margin-top: 200rpx;">
			<view class="dingwei">
				<view class="sishi xiaohei fonweight">{{$t('wangjimm.srsjh')}}</view>
				<view class="xiahuaxian margin_top6">
					<input type="number" :placeholder="$t('wangjimm.srzcsjh')" v-model="mobile">
				</view>
				<view class="xiahuaxian margin_top flexbetween">
					<input type="number" :placeholder="$t('wangjimm.sryzm')" v-model="yzm_code">
					<view class="xiaojin  textcenter"  style="width: 240rpx;" @click="sendyzm" v-show="codetext == 1">{{$t('wangjimm.hqyzm')}}</view>
					<view class="xiaojin  textcenter"  style="width: 240rpx;" v-show="codetext == 2">{{second}}s{{$t('wangjimm.cxhq')}}</view>
					<view class="xiaojin  textcenter"  style="width: 240rpx;" @click="sendyzm" v-show="codetext == 3">{{$t('wangjimm.wangjimm.cxfs')}}</view>
				</view>
				<view class="xiahuaxian margin_top">
					<input type="number" :placeholder="$t('wangjimm.xdmm')" v-model="newpassword">
				</view>
				<view class="xiahuaxian margin_top">
					<input type="number" :placeholder="$t('wangjimm.zcsrmm')" v-model="newpasswordt">
				</view>
				<view class="bigbtn margin_top6" @click="signIn()"  v-if="!liandiantype">{{$t('wangjimm.wc')}}</view>
				<view class="bigbtn margin_top6" v-if="liandiantype">{{$t('wangjimm.qd')}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				menutop: 0,
				codetext:1,
				second:59,
				mobile:'',
				yzm_code:'',
				newpassword:"",
				newpasswordt:"",
				 liandiantype:0,
				 imgcode:""
			}
		},
		onLoad() {
// #ifdef MP-WEIXIN
			this.menutop = uni.getMenuButtonBoundingClientRect().top * 2
			// #endif
		},
		methods: {

			//验证手机号
			isMobile(value) {
				let a = /^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(value);
				return a;
			},
			//发送验证码
			sendyzm() {
				let _this = this;
				if (_this.mobile == '') {
					httpRequest.toast(this.$t('wangjimm.srzcsjh'))
					return;
				}
				if (!_this.isMobile(_this.mobile)) {
					httpRequest.toast(this.$t('wangjimm.sjhcw'))
					return;
				}
				let device = uni.getSystemInfoSync();
				httpRequest.request('/api/sms/send', 'POST', {
					mobile: this.mobile,
					event: 'resetpwd',
				}, false, true, false).then(res => {
					if (res.code == 1) {
						_this.codetext = 2;
						_this.second = 59;
						let timer = setInterval(function() {
							if (_this.second > 1) {
								_this.second--;
							} else {
								clearInterval(timer);
								_this.codetext = 3;
							}
						}, 1000)
						httpRequest.toast(this.$t('wangjimm.fscg'))
					}else{
						httpRequest.toast(res.msg)
					}
				})
			},
			jumpurl(url) {
				uni.navigateTo({
					url
				})
			},
			checkaudio() {
				this.type = !this.type
			},
			signIn() {
				if (this.mobile == "") {
					httpRequest.toast(this.$t('wangjimm.srzcsjh'));
					return false;
				}
				if (!this.isMobile(this.mobile)) {
					httpRequest.toast(this.$t('wangjimm.sjhcw'))
					return;
				}
				if (this.yzm_code == "") {
					httpRequest.toast(this.$t('wangjimm.sryzm'));
					return false;
				}
				if (this.newpassword == "") {
					httpRequest.toast(this.$t('wangjimm.xdmm'))
					return false
				}
				if (this.newpasswordt == "") {
					httpRequest.toast(this.$t('wangjimm.zcsrmm'))
					return false
				}
				if (this.newpasswordt != this.newpassword) {
					httpRequest.toast(this.$t('wangjimm.mmbyz'))
					return false
				}
				this.liandiantype = 1
				uni.showLoading({
					mask: true,
					title: this.$t('wangjimm.qsh')
				})
				httpRequest.request('/api/user/resetpwd', 'GET', {
					mobile: this.mobile,
					captcha: this.yzm_code,
					newpassword: this.newpassword
				}).then(res => {
					uni.hideLoading()
					httpRequest.toast(res.msg);
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateBack(1)
						}, 1000)
					} else {
						this.liandiantype = 0
					}
				})
				// uni.navigateTo({
				// 	url:"/pages/login/userinfo"
				// })
			},

			// 返回上一页
			fhsyy() {
				uni.navigateBack(1)
			},
		}
	}
</script>

<style lang="scss" scoped>
	.dlbjt {
		width: 100%;
		height: 529rpx;
		position: absolute;
		top: 0;
		left: 0;
		z-index: 0;
	}

	.weixz {
		width: 24rpx;
		height: 24rpx;
		border: 1rpx solid #999999;
		border-radius: 50%;
	}

	.dingbu {
		height: 188rpx;
		background-size: 100% 100%;
		width: 100%;
		box-sizing: border-box;
		background-image: url('https://moveadd.yuntaiqi.com/uploads/20240105/db6453811b20bba0dd77019462806fe8.png');
	}
</style>